(function (global, factory) {
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  typeof define === 'function' && define.amd ? define([], factory) :
  global.littleCanvas = factory();
}(this, function () { 'use strict';

  function littleCanvas(canvas) {
    if (!canvas) {
      canvas = document.createElement('canvas');
      this.size = 128;
      canvas.width = this.size;
      canvas.height = this.size;
    } else {
      this.size = canvas.width;
    }

    var ctx = canvas.getContext('2d');
    
    this.canvas = canvas
    this.ctx = ctx;
    
    this.width = canvas.width
    this.height = canvas.height
  }

  littleCanvas.prototype.setSize = function(width, height) {
    this.size = width;
    this.width = width;
    
    if (height) {  
      this.height = height;
    } else {
      this.height = width
    }
    var canvas = this.canvas;
    canvas.width = this.size;
    canvas.height = this.height || this.size;
    return this;
  }

  littleCanvas.prototype.clear = function() {
    var canvas = this.canvas;
    var size = this.size;
    canvas.width = size;
    canvas.height = this.height || size;
    return this;
  }

  littleCanvas.prototype.draw = function(cf) {
    var ctx = this.ctx;
    ctx.save();
    ctx.beginPath();
    cf.call(this, ctx);
    ctx.closePath();
    ctx.restore();
    return this;
  }

  littleCanvas.prototype.pop = function() {
    return this.canvas;
  }

  return littleCanvas;

}))